package com.hahaliu.hahaliu.controller.user;

import com.hahaliu.hahaliu.common.result.Result;
import com.hahaliu.hahaliu.common.context.CurrentUser;
import com.hahaliu.hahaliu.pojo.vo.FollowVO;
import com.hahaliu.hahaliu.service.user.FollowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/follow")
@Api(tags = "用户端关注相关接口")
@Slf4j
public class FollowController {

	@Autowired
	private FollowService followService;
	@Autowired
	private CurrentUser currentUser;

	@GetMapping("/count")
	@ApiOperation("获取用户关注粉丝数")
	public Result<FollowVO> getCount(@RequestParam("uid") Integer uid) {
		FollowVO fansCount = followService.getFansCount(uid);

		return Result.success(fansCount);
	}

	@GetMapping("/isFollow")
    @ApiOperation("判断用户是否关注了某个用户")
    public Result<Boolean> isFollow(@RequestParam("uid") Integer uid, @RequestParam("followUid") Integer followUid) {
        Boolean isFollow = followService.isFollow(uid, followUid);

        return Result.success(isFollow);
    }

	@PostMapping("/follow")
	@ApiOperation("关注某个用户")
    public Result follow(@RequestParam("followUid") Integer followUid) {
		Integer currentId = currentUser.getUserId();
		followService.follow(currentId, followUid);

        return Result.success();
    }

}
